package logic

import (
	"context"

	"user/internal/svc"
	"user/pb/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserListByIDsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserListByIDsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserListByIDsLogic {
	return &GetUserListByIDsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// GetUserListByIDs 获取用户列表
func (l *GetUserListByIDsLogic) GetUserListByIDs(in *user.UserListByIDsRequest) (*user.UserListResponse, error) {
	list, total, err := l.svcCtx.UserExtendModel.FindListByIDs(l.ctx, in.Ids)
	if err != nil {
		return nil, err
	}

	data := make([]*user.UserInfo, 0)
	for _, u := range list {
		data = append(data, &user.UserInfo{Id: u.Id, Name: u.Name, Avatar: u.Avatar})
	}
	return &user.UserListResponse{Total: total, Data: data}, nil
}
